package com.hpeng.sys.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.hpeng.sys.service.Function;
import com.hpeng.sys.service.LoginUserMgr;
import com.hpeng.sys.vo.Menu;
import com.opensymphony.xwork2.ActionContext;

@Component("MenuAction")
@Scope("prototype")
public class MenuAction {
	@Resource
	private Function function;
	@Resource
	private LoginUserMgr loginUser;
	private List<Menu> menu;
	public List<Menu> getMenu() {
		return menu;
	}
	public void setMenu(List<Menu> menu) {
		this.menu = menu;
	}

	public String execute() {
		String userId = loginUser.getUserId(request());
		if ((userId != null) && (!"".equals(userId))) {
			this.menu = function.getMenu(userId);
		}
		return "success";
	}

	public HttpServletRequest request(){
		return ServletActionContext.getRequest();
	}
	public Map<String,Object> session(){
		return ActionContext.getContext().getSession();
	}
}